/**
 * Copyright (C), 2019-2023,
 * FileName: ContactsController
 * Author:   fanxquer
 * Date:     2023/7/6 16:15
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 邱富康           2023/7/6           1.0
 */
package com.hsteach.web.controller.contact;

import com.hsteach.common.annotation.Anonymous;
import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.R;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.framework.feign.client.uapi.vo.*;
import com.hsteach.framework.feign.client.xgk.dto.ret.GetParentsRet;
import com.hsteach.framework.feign.client.xgk.dto.ret.GetTeacherRet;
import com.hsteach.framework.feign.client.xgk.dto.ret.preschool.PreschoolGetParentsRet;
import com.hsteach.service.contact.ContactsService;
import com.hsteach.util.MyPager;
import com.hsteach.web.controller.visit.vo.ListStudentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈通讯录〉
 *
 * @author Qiu Fukang
 * @create 2023/7/6
 * @since 1.0.0
 */
@Api(value = "通讯录", tags = "通讯录")
@RestController
@RequestMapping("/contacts")
public class ContactsController extends BaseController {

    @Autowired
    private ContactsService contactsService;

    @GetMapping("/teacher/list")
    @ApiOperation("查询教师联系人列表")
    public TableDataInfo listTeacher(@RequestParam(value = "searchWord", required = false) String searchWord) {
        return getDataTable(contactsService.getTeachers(searchWord));
    }

    @GetMapping("/teacher/preschoolTeacher")
    @ApiOperation("查询幼教师联系人列表")
    public TableDataInfo preschoolTeachers(@RequestHeader(value = "accessToken") String accessToken,
                                           @RequestParam(value = "searchWord", required = false)String searchWord,
                                           @RequestParam(value = "eClassId", required = false) String eClassId ) {
        return getDataTable(contactsService.preschoolTeachers(accessToken,searchWord,eClassId));
    }

    @GetMapping("/teacher/pageList")
    @ApiOperation("查询教师联系人列表-分页")
    public TableDataInfo pageListTeacher(@RequestParam(value = "searchWord", required = false) String searchWord,
                                         @RequestParam(value = "pageNum") Integer pageNum,
                                         @RequestParam(value = "pageSize") Integer pageSize) {
        List<GetTeacherRet> teachers = contactsService.getTeachers(searchWord);
        TableDataInfo<ListStudentVo> pageRet = new TableDataInfo<>();
        MyPager pager = new MyPager<>();
        pager.setCurrentPages(pageNum);
        pager.setSize(pageSize);
        pager.setDataList(teachers);
        pageRet.setTotal(pager.getRecordCount());
        //获得分页结果
        pageRet.setRows(pager.getResultsList());
        return pageRet;
    }

    @GetMapping("/parent/list")
    @ApiOperation("查询家长联系人列表")
    public R<List<GetParentsRet>> listParent(@RequestParam(value = "searchWord", required = false) String searchWord) {
        return R.ok(contactsService.getParent(searchWord));
    }

    @GetMapping("/departTeacher/list")
    @ApiOperation("查询机关联系人列表")
    public R<LinkedHashMap<String, List<DepartTeacher>>> listdepartTeacher(@RequestParam(value = "searchWord", required = false) String searchWord) {
        return R.ok(contactsService.getDepartTeachers(searchWord));
    }

    @GetMapping("/leader/list")
    @ApiOperation("查询校长联系人列表")
    public R<Map<String, List<Leader>>> listLeader(@RequestParam(value = "searchWord", required = false) String searchWord,@RequestParam(value = "xxlType", required = false) String xxlType) {
        return R.ok(contactsService.getLeaders(searchWord,xxlType));
    }


    @GetMapping("/teacher/preschool/list")
    @ApiOperation("查询幼教教师联系人列表")
    public TableDataInfo listPreschoolTeacher(@RequestParam(value = "searchWord", required = false) String searchWord) {
        return getDataTable(contactsService.getPreschoolTeachers(searchWord));
    }

    @GetMapping("/school/list")
    @ApiOperation("获取所有学校信息列表")
    public R<List<SchoolListVO>> listSchool() {
        return R.ok(contactsService.listSchool());
    }

    @GetMapping("/v2/leader/list")
    @ApiOperation("查询校长联系人列表")
    public R<List<Leader>> listV2Leader(@RequestParam(value = "searchWord", required = false) String searchWord,@RequestParam(value = "schoolId", required = false) String schoolId) {
        return R.ok(contactsService.listV2Leader(searchWord,schoolId));
    }

    @GetMapping("/v3/leader/list")
    @ApiOperation("查询校长联系人列表")
    @Anonymous
    public R<LinkedHashMap<String,Map<String,List<Leader>>>> listV3Leader(@RequestParam(value = "searchWord", required = false) String searchWord) {
        return R.ok(contactsService.listV3Leader(searchWord));
    }

    @GetMapping("/parent/preschool/list")
    @ApiOperation("查询幼教家长联系人列表")
    public R<List<PreschoolGetParentsRet>> getPreschoolParentList(@RequestParam(value = "searchWord", required = false) String searchWord) {
        return R.ok(contactsService.getParentList(searchWord));
    }

    @GetMapping("/company/preschool/list")
    @ApiOperation("查询单位联系人列表")
    public R<List<Company>> getCompanyList(@RequestParam(value = "searchWord", required = false) String searchWord,
                                           @RequestParam(value = "organizeId", required = false) String organizeId,
                                           @RequestParam(value = "type", required = false) Integer type) {
        return R.ok(contactsService.getCompanyList(searchWord, organizeId, type));
    }


    @GetMapping("/three/getCompanyAndDeptList")
    @ApiOperation("查询单位、科室、部门列表")
    public R<List<CompanyAndDept>> getCompanyAndDeptList() {
        return R.ok(contactsService.getCompanyAndDeptList());
    }

}
